package cn.com.msui.service.identity.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.msui.dao.identity.UserDAO;
import cn.com.msui.domain.ViewItem;
import cn.com.msui.domain.identity.User;
import cn.com.msui.service.identity.UserService;

@Service("userService")
public class UserServiceImpl extends UserService {
	private UserDAO userDAO;

	public UserDAO getUserDAO() {
		return userDAO;
	}

	@Autowired
	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
		setDao(userDAO);
	}

	@Override
	public User getUserById(String id) throws Exception {
		return userDAO.selectByPrimaryKey(id);
	}

	@Override
	public void addUser(User user) throws Exception {
		userDAO.insertOneUser(user);
	}

	@Override
	public void register(User user) throws Exception {
		addUser(user);
	}

	@Override
	public List<User> getUsers(ViewItem view, User user) throws Exception {
		Map<String, Object> conditions = getPageCondition(view);
		conditions.put("user", user);
		return userDAO.selectUsers(conditions);
	}

	@Override
	public void removeUsers(String[] userIds) throws Exception {
		userDAO.deleteUsersById(userIds);
	}

	@Override
	public void modifyUser(User user) throws Exception {
		userDAO.updateOneUser(user);
	}

	@Override
	public User getUserByAccount(String account) throws Exception {
		return userDAO.selectOneUserByAccount(account);
	}
}
